Page({
  mixins: [require('../../mixin/common')],
  data: {
    inputShowed: false,
    inputVal: '',
    wordList:['nihao','湖南','夏天'],
    subjects:[]
  },
  query(options){
    let that = this
    let key = options.currentTarget.dataset.key
    console.log(key);
    this.setData({
      inputVal:''
    })
    //查询显示包含key关键字top250中的电影列表
    let db = wx.cloud.database()
    db.collection('top250')
    .get({
      success:(res)=>{  
          that.setData({
            subjects:res.data[0].subjects
          })
          //用关键字key过滤数据
          console.log(res);
          let tmpArray = this.data.subjects.filter((value, index, array)=>{
            return value.title.indexOf(key)!=-1
          })
          console.log(tmpArray);
          that.setData({
            subjects:tmpArray
          })
      }
    })
  },
  showInput() {
    this.setData({
      inputShowed: true,
    });
  },
  hideInput(options) {
    this.query(options)
    this.setData({
      inputVal: '',
      inputShowed: false,
    });

  },
  clearInput() {
    this.setData({
      inputVal: '',
    });
  },
  inputTyping(e) {
    this.setData({
      inputVal: e.detail.value,
    });
    let db = wx.cloud.database()
    let searchCollection = db.collection('search')
    searchCollection.get().then(res=>{
      console.log(res.data[0].subjects);
      res.data[0].subjects
      this.setData({
        wordList:res.data[0].subjects
      })
    })
  },
});
